//
//  FoodListViewController.m
//  Menu
//
//  Created by Lynn-Shin on 15/7/2.
//  Copyright (c) 2015年 lijiangang. All rights reserved.
//

#import "FoodListViewController.h"

@interface FoodListViewController ()

@end

@implementation FoodListViewController

-(void)dealloc{
    
    [_listTableV release];
    
    [super dealloc];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.listTableV = [[UITableView alloc] initWithFrame:[[UIScreen mainScreen] bounds] style:UITableViewStylePlain];
    [self.view addSubview:self.listTableV];
    
    self.listTableV.delegate = self;
    self.listTableV.dataSource = self;
    
    [self downLoadData];
    
    self.allListArray = [NSMutableArray array];
    
    // Do any additional setup after loading the view.
}

-(void)downLoadData{
    
    NSString *body = @"";
    if (self.section == 0) {
        if (self.item == 0) {
            
            body = @"sign_ran=1b73ff42633e2f687a586c6330822457&code=eba2f5eaeaa2d28b&client=4&order=0&keyword=%E7%BE%8A%E8%82%89";
        } else if (self.item == 1){
            
            body = @"sign_ran=4d249c4424939933b17a603b8c8063ca&code=4548618fdb6fd881&client=4&order=0&keyword=%E7%89%9B%E8%82%89";
        }
    }
    
    [AFNetWorkingYU netWorkWithURL:@"http://api.douguo.net/recipe/s/0/15" body:body resultBlock:^(id result) {
        
        NSMutableArray *array = [[result objectForKey:@"result"] objectForKey:@"recipes"];
        NSLog(@"//%@++",array);
        for (NSMutableDictionary *diet in array) {
            
            FoodList *foodList = [[FoodList alloc] initWithDic:diet];
            [self.allListArray addObject:foodList];
        }
        NSLog(@"%ld",self.allListArray.count);
        [self.listTableV reloadData];
//        NSLog(@"%@+++++",result);
    }];
    
//    [AFNTool post:@"http://api.douguo.net/recipe/s/0/15" Body:@"sign_ran=e1c5c4db68e3d43d80cd6d2f347402be&code=8ceaaae347ed9d5b&client=4&order=0&keyword=%E7%BE%8A%E8%82%89" HttpResult:JSON RequsetBodyStyle:BodyHttp success:^(id result) {
//        NSMutableDictionary *bigDic = [result objectForKey:@"result"];
//        NSLog(@"%@",bigDic);
//        
//    } failure:^(NSError *error) {
//        NSLog(@"失败");
//        NSLog(@"%@",error);
//        
//    }];
}

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    
    return 1;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    return self.allListArray.count;
}
//点击cell方法
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    
    [self.listTableV deselectRowAtIndexPath:indexPath animated:YES];
}
//自定义cell
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    static NSString *cellIndentifier = @"myCell";
    
    FoodListTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIndentifier];
    if (cell == nil) {
        
        cell = [[FoodListTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIndentifier];
    }
    
    cell.foodList = [self.allListArray objectAtIndex:indexPath.row];
    
    return cell;
}
//cell高度
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    return 120;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
